<template>
    <el-dialog title="新增字典" :visible="dataDictionaryAdd" @close="dialogClose" width="40%">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="dataDictionaryAdd" label-width="auto" class="demo-ruleForm">
            <!-- <el-form-item label="ID：" prop="id">
                <el-input type="text" v-model="ruleForm.id" disabled></el-input>
            </el-form-item> -->
            <el-form-item label="字典名称：" prop="name">
                <el-input type="text" v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="值：" prop="value">
                <el-input type="text" v-model="ruleForm.value"></el-input>
            </el-form-item>
            <el-form-item label="权重：" prop="sort">
                <el-input type="text" v-model="ruleForm.sort" disabled></el-input>
            </el-form-item>
            <el-form-item label="上级ID：" prop="parentid">
                <el-input type="text" v-model="ruleForm.parentid" disabled></el-input>
            </el-form-item>
            <el-form-item label="备注：" prop="remark">
                <el-input type="textarea" :rows="4" v-model="ruleForm.remark">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm()" class="pull-right margin-l-25">确定
                </el-button>
                <el-button @click="dialogClose" class="pull-right">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script>
import { addData } from '@/api/systemAdministrator/dataDictionary';
export default {
    name: 'dataDictionaryAdd',
    data () {
        return {
            ruleForm: {
                id: '',
                name: '',
                value: '',
                sort: '',
                parentid: '',
                remark:''
            },
            rules: {
                // id: [
                //     { required: true, message: '请输入字典ID', trigger: 'blur' }
                // ],
                name: [
                    { required: true, message: '请输入字典名称', trigger: 'blur' }
                ],
                value: [
                    { required: true, message: '请输入字典值', trigger: 'blur' }
                ],
                // sort: [
                //     { required: true, message: '请输入排序权重', trigger: 'blur' }
                // ],
                // parentid: [
                //     { required: true, message: '请输入上级ID', trigger: 'blur' }
                // ],
            }
        };

    },

    props: {
        dataDictionaryAdd: {
            type: Boolean
        },
    },
    methods: {

        submitForm () {
            this.$refs.dataDictionaryAdd.validate((valid) => {
                if (valid) {
                    addData(this.ruleForm).then((res) => {
                        if(res){
                            console.log(res.msg);
                            this.$emit('dialogClose');
                        }
                    })
                }
                else {
                    return
                }
            });
        },

        dialogClose () {
            this.$emit('dialogClose')
        }
    },
    mounted () {
        
    }


}
</script>
<style lang="less" scoped>

</style>